#include "FireParticleSystem.h"
#include <cmath>

using namespace neiderra::rendering;

int FireParticleSystem::update(double deltaT)
{
	Particles::iterator i = _particles.begin();
	for(;i!=_particles.end();i++)
	{
		PolyParticle* pp = (PolyParticle*)*i;
		if(pp->lifetime<=0) {
			pp->pos.y = 0;
			pp->lifetime = 40;
		}
		pp->lifetime -= deltaT/100;
		pp->pos.y += 0.001*deltaT;
	}
	return 1;
}

void FireParticleSystem::initParticles()
{
	int j=1;
	const float lifemax = getMaxLifetime()*0.001;
	using namespace std;
	const float lifestep = lifemax/getMaxParticles();
	float ls = lifestep;
	for(int i=0;i<getMaxParticles();i++)
	{
		if(j==4) j=1;
		PolyParticle* pp = (PolyParticle*)this->add();
		pp->lifetime = ls;
		pp->size = 0.5;
		pp->texture = _texture;
		pp->pos.y = 0;
		pp->pos.x = std::cos(6.28/j)*0.3;
		pp->pos.z = std::sin(6.28/j)*0.3;
		j++;
		ls += lifestep;
	}
}
